{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"code\":\"10105\",\"data\":0,\"desc\":\"illegal access|illegal X-CheckSum\",\"sid\":\"wsr00038f83@dx133a12ef4aeb6f2300\"}\n"
     ]
    }
   ],
   "source": [
    "import time,base64,hashlib\n",
    "def main():\n",
    "    x_appid = '5f93f7eb'\n",
    "    api_key = '755004eea85bc82afbc4e6b094361f97'\n",
    "    url = 'http://api.xfyun.cn/v1/service/v1/image_identify/face_verification'\n",
    "    x_time = str(int(time.time()))\n",
    "    param = {'auto_rotate': True}\n",
    "    param = json.dumps(param)\n",
    "    x_param = base64.b64encode(param.encode('utf-8'))\n",
    "    m2 = hashlib.md5()\n",
    "    m2.update(str(api_key + x_time + str(x_param, 'utf-8')).encode('utf-8'))\n",
    "    x_checksum = m2.hexdigest()\n",
    "    x_header = {\n",
    "        'X-Appid': x_appid,\n",
    "        'X-CurTime': x_time,\n",
    "        'X-CheckSum': x_checksum,\n",
    "        'X-Param': x_param,\n",
    "    }\n",
    "    with open(r'D:\\\\桌面\\tp1.png','rb') as f:\n",
    "        f1 = f.read()\n",
    "    with open(r'D:\\\\桌面\\tp2.png', 'rb') as f:\n",
    "        f2 = f.read()\n",
    "    f1_base64 = str(base64.b64encode(f1), 'utf-8')\n",
    "    f2_base64 = str(base64.b64encode(f2), 'utf-8')\n",
    "    data = {\n",
    "        'first_image': f1_base64,\n",
    "        'second_image': f2_base64,\n",
    "    }\n",
    "    req = requests.post(url, data=data, headers=x_header)\n",
    "    result = str(req.content, 'utf-8')\n",
    "    print(result)  \n",
    "    return\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
